﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace D3StatsClient.Model
{
    public class D3TrackerItem
    {
        public D3TrackerItem() { }

        public D3TrackerItem(string xmlData)
        {
            try
            {
                XElement itemData = XElement.Parse(xmlData);

                this.ID = int.Parse(itemData.Element("id").Value);
                this.Name = itemData.Element("name").Value;
                this.Quality = (ItemQuality)Enum.Parse(typeof(ItemQuality), itemData.Element("quality").Value);
                this.Location = itemData.Element("location").Value;
                this.Time = DateTime.Parse (itemData.Element("timestamp").Value);
                this.ItemLevel = int.Parse(itemData.Element("level").Value);
                this.MagicFind = int.Parse(itemData.Element("magicfind").Value);
                this.Server = itemData.Element("server").Value;
                this.IsPickedUp = bool.Parse(itemData.Element("IsPickedUp").Value);
                this.ItemLink = itemData.Element("ItemLink").Value;
            }
            catch { }
        }

        public int ID { get; set; }
        public string Name { get; set; }
        public ItemQuality Quality { get; set; }
        public string Location { get; set; }
        public DateTime Time { get; set; }
        public int ItemLevel { get; set; }
        public double MagicFind { get; set; }
        public string Server { get; set; }
        public bool IsPickedUp { get; set; }
        public string ItemLink { get; set; }

        public void Save(IStatsProvider stats)
        {
            stats.RecordDrop(this);
        }

        public void Update(IStatsProvider stats)
        {

            stats.UpdateItem(this);
        }
    }
}
